package com.elink.enginerring.company;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elink.enginerring.company.co.CompanyCo;
import com.elink.enginerring.company.service.ICompanyService;
import com.elink.enginerring.datasource.DataSourceContextHolder;
import com.elink.enginerring.datasource.DataSourceType;

@Controller
@RequestMapping("/view/company")
@Api(value="公司接口")
public class CompanyController {
	@Autowired
	private ICompanyService companyService;
	
	
	/**
	 * 跳转到博文列表
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/blog.htm",method=RequestMethod.GET)
	public String toBlog(HttpServletRequest request){
		request.setAttribute("userId", request.getParameter("userId"));
		request.setAttribute("type", request.getParameter("type"));
		return "blog/blog_list";
	}
	
	/**
	 * 跳转到课程列表
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/course.htm",method=RequestMethod.GET)
	public String toCourse(HttpServletRequest request){
		request.setAttribute("userId", request.getParameter("userId"));
		return "course/course_list";
	}
	/**
	 * 分页获取公司接口
	 * @param co
	 * @return
	 */
	@RequestMapping(value="/getList",method=RequestMethod.GET)
	@ApiOperation(value="获取列表",httpMethod="GET",notes="分页获取公司接口")
	@ResponseBody
	public Map<String, Object>getList(@ModelAttribute @Valid CompanyCo co ){
		DataSourceContextHolder.setDbType(DataSourceType.DBUSER);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		return companyService.getList(co);
	}
	
	/**
	 * 获取公司详情
	 * @param companyId
	 * @return
	 */
	@RequestMapping(value="/getInfo",method=RequestMethod.GET)
	@ApiOperation(value="公司详情",httpMethod="GET",notes="获取公司详情")
	@ResponseBody
	public Map<String, Object>getInfo(@ApiParam(value="公司的主键",required=true)@RequestParam(value="companyId")String companyId){
		DataSourceContextHolder.setDbType(DataSourceType.DBUSER);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		return companyService.getInfo(companyId);
	}
	
	/**
	 * 审核企业
	 * @param ids
	 * @return
	 */
	@RequestMapping(value="/addAuth",method=RequestMethod.GET)
	@ApiOperation(value="审核问答",httpMethod="GET",notes="审核企业")
	@ResponseBody
	public Map<String, Object>addAuth(
	@ApiParam(value="企业主键ids，用逗号进行分割",required=true)@RequestParam(value="ids",required=true)String ids,
	@ApiParam(value="处理意见，1--审核通过，2--不通过审核",required=true)@RequestParam(value="authStatus",required=true,defaultValue="0")int authStatus){
		
		DataSourceContextHolder.setDbType(DataSourceType.DBUSER);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		
		return companyService.addAuth(ids,authStatus);
	}
}
